package com.doge.config.realm;

import com.doge.bean.auth.MarketToken;
import com.doge.bean.pojo.admin.Admin;
import com.doge.bean.pojo.user.User;
import com.doge.mapper.UserMapper;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: doge
 * @description:
 * @author: Keyu Li
 * @create: 2021-12-01 19:27
 **/

@Component
public class WxRealm extends AuthorizingRealm {

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        MarketToken token = (MarketToken) authenticationToken;
        User user = (User) token.getUser();
        String credential = user.getPassword();
        // 与token中的密码进行比对(自动)，返回 AuthenticationInfo
        return new SimpleAuthenticationInfo(user,credential,this.getName());
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        System.out.println("WX REALM doGetAuthorizationInfo");
        return null;
    }

}
